/**
 * @author Pieter Michels / wellconsidered
 * pieter@wellconsidered.be
 *
 * Open source under the GNU Lesser General Public License (http://www.opensource.org/licenses/lgpl-license.php)
 * Copyright © 2009 Pieter Michels / wellconsidered
 * 
 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License 
 * as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License along with this library; 
 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */
 
package be.wellconsidered.apis.lighthouse.connectors
{
	import be.wellconsidered.logging.Logger;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.HTTPStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class AbstractConnector extends EventDispatcher
	{
		protected var _sURL:String;
		
		protected var _request:URLRequest;
		protected var _loader:URLLoader;
		
		public function AbstractConnector(url:String)
		{
			_sURL = url;
			
			_loader = new URLLoader(null);
			_request = new URLRequest();
			
			createConnector();
		}
		
		protected function createConnector():void
		{
			_loader.addEventListener(Event.COMPLETE, onConnectorComplete, false, 0, true);
			_loader.addEventListener(IOErrorEvent.IO_ERROR, IOFaultHandler);
			_loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpFaultHandler);
			_loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityFaultHandler);
			
			_request.contentType = "text/xml";
			_request.url = _sURL;
		}
		
		protected function load():void
		{
			_loader.load(_request);
		}
		
		protected function onConnectorComplete(e:Event):void
		{
			Logger.log("OnGetComplete");			
		}
		
		protected function IOFaultHandler(e:IOErrorEvent):void
		{
			Logger.log("IOFaultHandler");
		}
		
		protected function httpFaultHandler(e:HTTPStatusEvent):void
		{
			Logger.log("httpFaultHandler");
		}
		
		protected function securityFaultHandler(e:SecurityErrorEvent):void
		{
			Logger.log("securityFaultHandler");
		}
	}
}